package com.backend.teamapi.controller;

import com.backend.teamapi.dto.ApiDocumentRequestDTO;
import com.backend.teamapi.dto.ApiDocumentResponseDTO;
import com.backend.teamapi.service.ApiDocumentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/documents")
public class ApiDocumentController {

    @Autowired
    private ApiDocumentService apiDocumentService;

    // 创建接口文档
    @PostMapping
    public ApiDocumentResponseDTO createDocument(@RequestBody ApiDocumentRequestDTO dto,
                                                 @RequestParam Long userId) {
        return apiDocumentService.createDocument(dto, userId);
    }

    // 查询某团队的所有接口文档
    @GetMapping("/team/{teamId}")
    public List<ApiDocumentResponseDTO> getByTeam(@PathVariable Long teamId) {
        return apiDocumentService.getDocumentsByTeam(teamId);
    }

    // 修改接口文档
    @PutMapping("/{id}")
    public ApiDocumentResponseDTO updateDocument(@PathVariable Long id,
                                                 @RequestBody ApiDocumentRequestDTO dto,
                                                 @RequestParam Long userId) {
        return apiDocumentService.updateDocument(id, dto, userId);
    }

    // 删除接口文档
    @DeleteMapping("/{id}")
    public String deleteDocument(@PathVariable Long id,
                                 @RequestParam Long userId) {
        apiDocumentService.deleteDocument(id, userId);
        return "Document deleted successfully";
    }

}
